import { useDispatch } from "react-redux";
import "./index.scss";
import { addCart, removeCart } from "../../store/modules/takeaway";

const Count = ({ food }) => {
  const dispatch = useDispatch();
  return (
    <div className="goods-count">
      <span className="minus" onClick={() => dispatch(removeCart(food))}>
        -
      </span>
      <span className="count">{food.count || 0}</span>
      {/* 触发仓库中的修改购物车列表的方法并传递当前商品信息 */}
      <span className="plus" onClick={() => dispatch(addCart(food))}>
        +
      </span>
    </div>
  );
};

export default Count;
